package org.keyroy.map.core.manages;

import java.util.ArrayList;
import java.util.List;

import org.keyroy.map.core.sprite.Sprite;
import org.keyroy.util.tag.Tag;
import org.keyroy.util.tag.XmlObject;

public class ResourcePack extends XmlObject {
	public List<Sprite> sprites = new ArrayList<Sprite>();
	public String name;

	@Override
	public void initTag(Tag tag) {
		tag.addParameter("name", name);
		StringBuffer buffer = new StringBuffer();
		for (int i = 0; i < sprites.size(); i++) {
			if (i != 0) {
				buffer.append(',');
			}
			buffer.append(String.valueOf(sprites.get(i).ID));
		}
		tag.addParameter("sprites", buffer.toString());
	}

	@Override
	public void initObj(Tag tag) {
		name = tag.getParameterValue("name");

		String piecesString = tag.getParameterValue("sprites");
		String[] strings = piecesString.split(",");
		for (int i = 0; i < strings.length; i++) {
			sprites.add(ResourceManage.getSprite(Integer.parseInt(strings[i])));
		}
	}

}
